﻿// CChromParsDlg.cpp: 实现文件
//

#include "stdafx.h"
#include "DC-QC.h"
#include "CChromParsDlg.h"
#include "afxdialogex.h"
#include "DirDialog.h"

// CChromParsDlg 对话框

IMPLEMENT_DYNAMIC(CChromParsDlg, CDialogEx)

CChromParsDlg::CChromParsDlg(CWnd* pParent /*=nullptr*/)
	: CDialogEx(IDD_CHROMPARSDLG, pParent)
{
	m_nCurID = -1;
	m_nType=0;
}

CChromParsDlg::~CChromParsDlg()
{
}

void CChromParsDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialogEx::DoDataExchange(pDX);
	DDX_Text(pDX, IDC_PT1, m_dPt1);
	DDX_Text(pDX, IDC_PT2, m_dPt2);
	DDX_Text(pDX, IDC_PT3, m_dPt3);
	DDX_Text(pDX, IDC_PT4, m_dPt4);
	DDX_Text(pDX, IDC_PT5, m_dPt5);
	DDX_Text(pDX, IDC_PT6, m_dPt6);
	DDX_Text(pDX, IDC_PT7, m_dPt7);
	DDX_Text(pDX, IDC_WT1, m_dPw1);
	DDX_Text(pDX, IDC_WT2, m_dPw2);
	DDX_Text(pDX, IDC_WT3, m_dPw3);
	DDX_Text(pDX, IDC_WT4, m_dPw4);
	DDX_Text(pDX, IDC_WT5, m_dPw5);
	DDX_Text(pDX, IDC_WT6, m_dPw6);
	DDX_Text(pDX, IDC_WT7, m_dPw7);
	DDX_Text(pDX, IDC_XL, m_dXL);
	DDX_Text(pDX, IDC_FOLDER, m_strFolder);
}


BEGIN_MESSAGE_MAP(CChromParsDlg, CDialogEx)
	ON_BN_CLICKED(IDOK, &CChromParsDlg::OnBnClickedOk)
	ON_BN_CLICKED(IDC_BTSEL, &CChromParsDlg::OnBnClickedBtsel)
	ON_WM_PAINT()
	ON_WM_CTLCOLOR()
END_MESSAGE_MAP()


// CChromParsDlg 消息处理程序

BOOL CChromParsDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// TODO:  在此添加额外的初始化
	if(m_nType==0)
	{
		m_dPt1 = gl.gcCi.scA[0].RealyTime;
		m_dPt2 = gl.gcCi.scA[1].RealyTime;
		m_dPt3 = gl.gcCi.scA[2].RealyTime;
		m_dPt4 = gl.gcCi.scA[3].RealyTime;
		m_dPt5 = gl.gcCi.scA[4].RealyTime;
		m_dPt6 = gl.gcCi.scA[5].RealyTime;
		m_dPt7 = gl.gcCi.scA[6].RealyTime;
		m_dPw1 = gl.gcCi.scA[0].Wrap;
		m_dPw2 = gl.gcCi.scA[1].Wrap;
		m_dPw3 = gl.gcCi.scA[2].Wrap;
		m_dPw4 = gl.gcCi.scA[3].Wrap;
		m_dPw5 = gl.gcCi.scA[4].Wrap;
		m_dPw6 = gl.gcCi.scA[5].Wrap;
		m_dPw7 = gl.gcCi.scA[6].Wrap;
		m_dXL = gl.m_dMinXLA;
	}
	else
	{
		m_dPt1 = gl.gcCi.scB[0].RealyTime;
		m_dPt2 = gl.gcCi.scB[1].RealyTime;
		m_dPt3 = gl.gcCi.scB[2].RealyTime;
		m_dPt4 = gl.gcCi.scB[3].RealyTime;
		m_dPt5 = gl.gcCi.scB[4].RealyTime;
		m_dPt6 = gl.gcCi.scB[5].RealyTime;
		m_dPt7 = gl.gcCi.scB[6].RealyTime;
		m_dPw1 = gl.gcCi.scB[0].Wrap;
		m_dPw2 = gl.gcCi.scB[1].Wrap;
		m_dPw3 = gl.gcCi.scB[2].Wrap;
		m_dPw4 = gl.gcCi.scB[3].Wrap;
		m_dPw5 = gl.gcCi.scB[4].Wrap;
		m_dPw6 = gl.gcCi.scB[5].Wrap;
		m_dPw7 = gl.gcCi.scB[6].Wrap;
		m_dXL = gl.m_dMinXLB;
		GetDlgItem(IDC_FOLDER)->EnableWindow(FALSE);
		GetDlgItem(IDC_BTSEL)->EnableWindow(FALSE);
	}
	m_strFolder = gl.gcCi.strFolder;
	if(m_nType==0)
	{
		SetWindowText(_T("通道A峰积分参数"));
	}
	else
	{
		SetWindowText(_T("通道B峰积分参数"));
	}
	UpdateData(FALSE);
	return TRUE;  // return TRUE unless you set the focus to a control
	// 异常: OCX 属性页应返回 FALSE
}

void CChromParsDlg::OnBnClickedOk()
{
	// TODO: 在此添加控件通知处理程序代码
	UpdateData(TRUE);
	if(m_nType==0)
	{
		gl.gcCi.scA[0].RealyTime = m_dPt1;
		gl.gcCi.scA[1].RealyTime = m_dPt2;
		gl.gcCi.scA[2].RealyTime = m_dPt3;
		gl.gcCi.scA[3].RealyTime = m_dPt4;
		gl.gcCi.scA[4].RealyTime = m_dPt5;
		gl.gcCi.scA[5].RealyTime = m_dPt6;
		gl.gcCi.scA[6].RealyTime = m_dPt7;

		gl.gcCi.scA[0].Wrap = m_dPw1;
		gl.gcCi.scA[1].Wrap = m_dPw2;
		gl.gcCi.scA[2].Wrap = m_dPw3;
		gl.gcCi.scA[3].Wrap = m_dPw4;
		gl.gcCi.scA[4].Wrap = m_dPw5;
		gl.gcCi.scA[5].Wrap = m_dPw6;
		gl.gcCi.scA[6].Wrap = m_dPw7;
		gl.m_dMinXLA = m_dXL;
		SaveINIFile(_T("Setting"), _T("MinXlA"), gl.m_dMinXLA);
	}
	else
	{
		gl.gcCi.scB[0].RealyTime = m_dPt1;
		gl.gcCi.scB[1].RealyTime = m_dPt2;
		gl.gcCi.scB[2].RealyTime = m_dPt3;
		gl.gcCi.scB[3].RealyTime = m_dPt4;
		gl.gcCi.scB[4].RealyTime = m_dPt5;
		gl.gcCi.scB[5].RealyTime = m_dPt6;
		gl.gcCi.scB[6].RealyTime = m_dPt7;

		gl.gcCi.scB[0].Wrap = m_dPw1;
		gl.gcCi.scB[1].Wrap = m_dPw2;
		gl.gcCi.scB[2].Wrap = m_dPw3;
		gl.gcCi.scB[3].Wrap = m_dPw4;
		gl.gcCi.scB[4].Wrap = m_dPw5;
		gl.gcCi.scB[5].Wrap = m_dPw6;
		gl.gcCi.scB[6].Wrap = m_dPw7;
		gl.m_dMinXLB = m_dXL;
		SaveINIFile(_T("Setting"), _T("MinXlB"), gl.m_dMinXLB);
	}
	gl.gcCi.strFolder = m_strFolder;


	CDialogEx::OnOK();
}


void CChromParsDlg::OnBnClickedBtsel()
{
	// TODO: 在此添加控件通知处理程序代码
	CDirDialog dlg;
	if (dlg.DoBrowse(this) == IDOK)
		m_strFolder = dlg.m_strPath;
	UpdateData(FALSE);
}


void CChromParsDlg::OnPaint()
{
	CPaintDC dc(this); // device context for painting
					   // TODO: 在此处添加消息处理程序代码
					   // 不为绘图消息调用 CDialogEx::OnPaint()
	CRect rect;
	GetClientRect(&rect);

	CBitmap ClientScreen, *pOldBitmap;
	CRect UpdateRect(rect);
	CDC MDC;
	MDC.CreateCompatibleDC(&dc);
	ClientScreen.CreateCompatibleBitmap(&dc, rect.Width(), rect.Height());
	pOldBitmap = MDC.SelectObject(&ClientScreen);
	MDC.FillSolidRect(UpdateRect, RGB(255, 255, 255));
	Draw(&MDC, rect);
	dc.BitBlt(UpdateRect.left, UpdateRect.top,
		UpdateRect.right - UpdateRect.left,
		UpdateRect.bottom - UpdateRect.top,
		&MDC, UpdateRect.left, UpdateRect.top, SRCCOPY);
	MDC.SelectObject(pOldBitmap);

	ClientScreen.DeleteObject();
	MDC.DeleteDC();
}

void	CChromParsDlg::Draw(CDC* pDC, CRect rt)
{
	DrawInBorder(pDC, rt);
	rt.DeflateRect(1, 1, 1, 1);
	BxGradientFill(pDC, rt, BACKCOLOR1, BACKCOLOR1, 1);
}


HBRUSH CChromParsDlg::OnCtlColor(CDC* pDC, CWnd* pWnd, UINT nCtlColor)
{
	HBRUSH hbr = CDialogEx::OnCtlColor(pDC, pWnd, nCtlColor);

	// TODO:  在此更改 DC 的任何特性
	if (nCtlColor == CTLCOLOR_STATIC)
	{
		pDC->SetBkMode(TRANSPARENT);
		return gl.m_brBack1;
	}

	// TODO:  如果默认的不是所需画笔，则返回另一个画笔
	return hbr;
}

